/*
 * igo: com.cctv.igo.admin.scheduler.dto.TriggerTypeDefinition.java Create On 2011-5-3 下午08:02:04 By Q-Wang
 * $Revision: 1.2 $
 */
package com.ctvit.scheduler.dto;

import java.io.Serializable;
import java.util.Map;

import com.ctvit.scheduler.parser.TriggerParser;
import com.ctvit.scheduler.service.ScheduleService;
import com.ctvit.framework.web.context.ContextHolder;

/**
 * @author <a href="mailto:apeidou@gmail.com">Q-Wang</a>
 *
 */
public class TriggerTypeDefinition implements Serializable {

	private static Map<String,TriggerTypeDefinition> triggerTypes;

	/**
	 * @return the triggerTypes
	 */
	public static Map<String,TriggerTypeDefinition> getTriggerTypes() {
		if (triggerTypes==null) {
			triggerTypes = ContextHolder.getBean(ScheduleService.class).getTriggerTypeDefinition();
		}
		return triggerTypes;
	}

	/**
	 * @param triggerTypes the triggerTypes to set
	 */
	public static void setTriggerTypes(Map<String,TriggerTypeDefinition> triggerTypes) {
		if (TriggerTypeDefinition.triggerTypes!=null) {
			throw new IllegalStateException("Scheduler Trigger Types Already resolved.");
		}
		TriggerTypeDefinition.triggerTypes = triggerTypes;
	}

	public static TriggerParser getTriggerParser(String type) {
		TriggerTypeDefinition typeDefinition = getTriggerTypes().get(type);
		if (typeDefinition==null) {
			throw new IllegalStateException("");
		}
		return typeDefinition.getParserInstance();
	}

	private TriggerParser parserInstance;

	/**
	 * @return the parserInstance
	 */
	public TriggerParser getParserInstance() {
		return parserInstance;
	}

	/**
	 * @param parserInstance the parserInstance to set
	 */
	public void setParserInstance(TriggerParser parserInstance) {
		this.parserInstance = parserInstance;
	}

	private String type;

	private String parser;

	private String description;

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the parser
	 */
	public String getParser() {
		return parser;
	}

	/**
	 * @param parser the parser to set
	 */
	public void setParser(String parser) {
		this.parser = parser;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
}
